import { defineStore } from 'pinia'
import { store } from '../index'

interface AppState {
  userInfo: any
  token: string
  isReload: boolean
}
export const useAppStore = defineStore('app', {
  state: (): AppState => {
    return {
      userInfo: null,
      token: '',
      isReload: true,// 刷新当前页
    }
  },
  getters: {
    getUserInfo(): any {
      return this.userInfo
    },
    getToken(): string {
      return this.token
    },
    getIsReload(): boolean {
      return this.isReload
    },
  },
  actions: {
    setToken(token: string) {
      this.token = token
    },
    setUserInfo(userInfo: string) {
      this.userInfo = userInfo
    },
    // 刷新
    setReload() {
      this.isReload = false
      setTimeout(() => {
        this.isReload = true
      }, 50)
    },
  }
})

export const useAppStoreWithOut = () => {
  return useAppStore(store)
}
